home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 22
/
Cream of the Crop 22.iso
/
windows
/
cm95_10.zip
/
INTERNET.DLL
/
TEXT
/
WILTIME
< prev
Wrap
Text File
|
1996-10-29
|
4KB
|
152 lines
AddExtender ("WXSock32i.dll")
IntControl (35, 500, 0, 0, 0)
sTitle = "ClockMan GetTime pgm"
bOK = @TRUE
sDial = "<dialupname>"
nMaxRedial = <numredials>
nRedialDelay = 10
sHost = "<timeserveraddr>"
sErrDesc = ""
;Dial our host (unless user is on a direct connect)...
hConn = 0
nNumRedials = 0
if (sDial <> "")
:DialIt
hConn = DUNConnect (sDial)
nErr = SGetLastErr ()
if (!hConn)
switch nErr
case @SErrNotFound
sErrDesc = "Couldn't connect to %sDial%: no such dial-up"
break
case @SErrBusy
if (nNumRedials <= nMaxRedial)
nNumRedials = nNumRedials + 1
Delay (nRedialDelay)
goto DialIt
else
sErrDesc = "Couldn't connect to %sDial%: Line busy"
endif
break
case @SErrNoAnswer
if (nNumRedials <= nMaxRedial)
nNumRedials = nNumRedials + 1
Delay (nRedialDelay)
goto DialIt
else
sErrDesc = "Couldn't connect to %sDial%: No answer"
endif
break
case @SErrVoice
sErrDesc = "Couldn't connect to %sDial%: A human answered"
break
case nErr ; <--default
sErrDesc = "Couldn't connect to %sDial% - error %nErr%"
endswitch
bOK = @FALSE
goto LogIt
else
if (nErr == @SAlready)
; We're already connected. Don't hang up when this event is thru...
hConn = 0
endif
endif
endif
; Create a socket...
hSock = SOpen ()
if (hSock==@SErrSocket)
nErr = SGetLastErr ()
sErrDesc = "Couldn't create socket - error %nErr%"
bOK = @FALSE
goto HangUp
endif
; Connect it up...
nRet = SConnect (hSock, sHost, "time")
if (nRet <> @TRUE)
nErr = SGetLastErr ()
switch nErr
case @SErrHostName
sErrDesc = "Host ""%sHost%"" not found. (Misspelled, or no longer exists.)"
break
case 10060
sErrDesc = "Timed out trying to connect to ""%sHost%""."
break
case @SErrBusy
sErrDesc = "Couldn't connect to ""%sHost%"".%@CRLF%(Server busy.)"
break
case @SErrNoConn
sErrDesc = "Couldn't connect to ""%sHost%"".%@CRLF%(Server down, or they don't offer a time server.)"
break
case nErr ; <--default
sErrDesc = "Couldn't connect to ""%sHost%"" - WinSock error %nErr%"
endswitch
bOK = @FALSE
goto CloseSocket
endif
; Time server sent us the time immediately upon connect...
dwRawTime = SRecvNum32 (hSock)
dwPrevTime = CMGetSysTime ()
if (!dwRawTime)
; Oh, maybe they require a CR/LF first like RFC 868 claims they should?...
SSendLine (hSock, "")
dwRawTime = SRecvNum32 (hSock)
dwPrevTime = CMGetSysTime ()
endif
if (!dwRawTime)
sErrDesc = "No response from time server @ ""%sHost%""."
bOK = @FALSE
else
; Immediately update our system time...
dwNewTime = dwRawTime - 2208988800; Convert to secs since 1/1/70 from 1/1/00
CMSetSysTime (dwNewTime)
endif
; If user hit Ctrl+Break, WIL will bring us here...
:Cancel
; Close the socket...
:CloseSocket
nRet = SClose (hSock)
; Hang up...
:HangUp
if (hConn)
nRet = DUNDisconnect (hConn)
endif
; Log what we did...
:LogIt
if bOK == @TRUE
; Finally, log the adjustment...
dwOffset = dwNewTime - dwPrevTime
if (dwOffset > 0)
sLog = "Turned the clock forward by %dwOffset% seconds"
else
if (dwOffset < 0)
dwOffset = -dwOffset
sLog = "Turned the clock back by %dwOffset% seconds"
else
sLog = "No adjustment needed to the system clock!"
endif
endif
else
sLog = strcat ("Error attempting to adjust time:", @CRLF, sErrDesc)
endif
CMLogMessage (sLog)
Display (5, sTitle, sLog)
~